const { wrapApiData } = require(`../util.js`);

const mock = require("./mock");
module.exports = (util) => {
  const {
    libObj: { mockjs },
  } = util;
  return {
    api: {
      // 创建接口并使用 mockjs 生成数据
      "get /api/consumer/keywords": wrapApiData(
        mockjs.mock({
          "data|5-20": mock.keywords,
        }),
      ),
      "get /api/consumer/new-products"(req, res) {
        res.json(
          wrapApiData(
            mockjs.mock({
              "data|3": mock.newProducts,
            }),
          ),
        );
      },
      "post /api/consumer/products"(req, res) {
        res.json(
          wrapApiData(
            mockjs.mock({
              "data|20-40": mock.products,
            }),
          ),
        );
      },
      "get /api/consumer/carts": wrapApiData(
        mockjs.mock({
          "data|5-20": mock.carts,
        }),
      ),
    },
  };
};
